/* eslint-disable */
import Vue from 'vue';
import Vuex from 'vuex';
// import Store from '../pages/ops-manage/store';
Vue.use(Vuex);
// const store = new Vuex.Store(Store);
// const MsgVue = new Vue({ store });
const WhiteList = ['/birdnest/api/device/config/'];
export default (params) => {
  if (params.method && params.method === 'GET') {
    if (params.query) {
      let param = '';
      let obj = eval(params.query);
      for (let item in obj) {
        param += item + '=' + obj[item] + '&';
      }
      if (param && param.length > 0) {
        param = param.substr(0, param.length - 1);
      }
      params.url = params.url + '?' + param;
    }
  }
  return new Promise((resolve, reject) => {
    const token = localStorage.getItem('token') || '';
    if (token) {
      $.ajaxSetup({
        headers: {
          'authorization': token
        },
        contentType: 'application/json; charset=utf-8'
      });
    }
    $.ajax({
      url: params.url,
      type: params.method,
      data: JSON.stringify(params.data),
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success(data) {
        resolve(data);
      },
      error(err) {
        reject(err);
      }
    });
  });
};
